package com.matrix.java.chap_06;

import java.util.Scanner;

/*
   几何：点的位置
 */
public class Ex6_39 {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        System.out.println("Enter three points for pO, p1,and p2: ");
        double x0 = input.nextDouble();
        double y0 = input.nextDouble();
        double x1 = input.nextDouble();
        double y1 = input.nextDouble();
        double x2 = input.nextDouble();
        double y2 = input.nextDouble();
        input.close();
        if (leftOfTheLine(x0,y0,x1,y1,x2,y2)){
            System.out.println("left");
        }else if (onTheSameLine(x0,y0,x1,y1,x2,y2)&&onTheLineSegment(x0,y0,x1,y1,x2,y2)){
            System.out.println("线段上");
        }else if (onTheSameLine(x0,y0,x1,y1,x2,y2)){
            System.out.println("线上");
        }else {
            System.out.println("right");
        }
    }

    private static boolean leftOfTheLine(double x0, double y0, double x1, double y1, double x2, double y2) {
        double result = (x1-x0)*(y2-y0)-(x2-x0)*(y1-y0);
        if (result >0){
            return true;
        }
        return false;
    }
    private static boolean onTheSameLine(double x0, double y0, double x1, double y1, double x2, double y2) {
        double result = (x1-x0)*(y2-y0)-(x2-x0)*(y1-y0);
        if (result ==0){
            return true;
        }
        return false;
    }
    private static boolean onTheLineSegment(double x0, double y0, double x1, double y1, double x2, double y2) {
        if ((x0>x2&&x1<x2)||(x0<x2&&x1>x2)){
            return true;
        }
        return false;
    }
}
